package com.coreJava.v2.ch01.streams;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

public class CountLongWords {
    public static void main(String[] args) throws IOException {
        String projectRoot = System.getProperty("user.dir");
        System.out.println(projectRoot);
        Path path = Paths.get(projectRoot+"/gutenberg/alice30.txt");
        System.out.println(path);
        byte[] bytes = Files.readAllBytes(path);
        String contents = new String(bytes, StandardCharsets.UTF_8);
        List<String> words = Arrays.asList(contents.split("\\PL+"));
        long count = 0;
        for (String w : words)
        {
            if (w.length() > 12) count++;
        }
        System.out.println(count);

        count = words.stream().filter(w -> w.length() > 12).count();
        System.out.println(count);
        count=words.parallelStream().filter(w->w.length()>12).count();
        System.out.println(count);
    }
}
